package com.demo.controller;

import com.demo.entity.ThreadParam;
import com.demo.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/test")
@Api(value = "测试一下")
public class TestController {

    @Resource(name = "defaultAsyncPoolTaskExecutor")
    private ThreadPoolTaskExecutor threadPoolTaskExecutor;
 
 
    @GetMapping("/userinfo")
    @ApiOperation("获取用户列表信息")
    public User getUserInfo(){
 
        User user = new User();
 
        return user;
    }

    @PostMapping("/insertUser")
    @ApiOperation("添加用户")
    public User insertUserInfo(@RequestBody User user){

        return user;
    }

    @PostMapping("test/updateTheadParam")
    public void updateTheadParam(@RequestBody ThreadParam threadParam){
        Integer corePoolSize = threadParam.getCorePoolSize();
        int corePoolSize1 = threadPoolTaskExecutor.getCorePoolSize();
        System.out.println("原本的核心线程数：" + corePoolSize1 + "修改为："+corePoolSize);
        threadPoolTaskExecutor.setCorePoolSize(corePoolSize);
    }

    @PostMapping("test/getTheadParam")
    public Integer updateTheadParam(){
        return threadPoolTaskExecutor.getCorePoolSize();
    }


}